package com.wl.jetpackdemo.chat

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.BaseQuickAdapter
import com.wl.jetpackdemo.databinding.ActivityMainMessageBinding

class MessageMainActivity : AppCompatActivity() {
    private lateinit var binding: ActivityMainMessageBinding
    private lateinit var adapter: MessageSessionAdapter


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainMessageBinding.inflate(layoutInflater)
        setContentView(binding.root)

        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        title = "聊天首页"

        binding.rvList.layoutManager = LinearLayoutManager(this)
        adapter = MessageSessionAdapter()
        binding.rvList.adapter = adapter
        adapter.setOnItemClickListener { baseQuickAdapter: BaseQuickAdapter<*, *>, view: View, i: Int ->
            val session = baseQuickAdapter.data[i]
            startActivity(Intent(this, MessageActivity::class.java))
        }
        mockData()
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        when(item.itemId) {
            android.R.id.home -> finish()
        }

        return super.onOptionsItemSelected(item)
    }

    private fun mockData() {
        var list = ArrayList<MessageSession>()
        list.add(MessageSession(1, false,"张三", "", "最近怎么样？", 0))
        list.add(MessageSession(2, true, "李四", "", "哈哈哈大幅度发的发的方法的机会将发动机号", 0))
        list.add(MessageSession(2, false,"李四", "", "哈哈哈大幅度发的发的方法的机会将发动机号", 0))
        list.add(MessageSession(2, false,"李四", "", "哈哈哈大幅度发的发的方法的机会将发动机号", 0))
        list.add(MessageSession(2, false,"李四", "", "哈哈哈大幅度发的发的方法的机会将发动机号", 0))
        list.add(MessageSession(2, false,"李四", "", "哈哈哈大幅度发的发的方法的机会将发动机号", 0))
        list.add(MessageSession(2, false,"李四", "", "哈哈哈大幅度发的发的方法的机会将发动机号", 0))
        list.add(MessageSession(2, false,"李四", "", "哈哈哈大幅度发的发的方法的机会将发动机号", 0))
        list.add(MessageSession(2, false,"李四", "", "哈哈哈大幅度发的发的方法的机会将发动机号", 0))
        list.add(MessageSession(2, false,"李四", "", "哈哈哈大幅度发的发的方法的机会将发动机号", 0))
        list.add(MessageSession(2, false,"李四", "", "哈哈哈大幅度发的发的方法的机会将发动机号", 0))
        list.add(MessageSession(2, false,"李四", "", "哈哈哈大幅度发的发的方法的机会将发动机号", 0))
        list.add(MessageSession(2, false,"李四", "", "哈哈哈大幅度发的发的方法的机会将发动机号", 0))
        adapter.setNewInstance(list)
    }
}